"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.StepItemWebLayout = StepItemWebLayout;

var _react = _interopRequireWildcard(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _configContext = require("../../../../extends/configContext");

var _stepContext = require("../../stepContext");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function StepItemWebLayout(_ref) {
  var _classNames2, _classNames4;

  var index = _ref.index,
      className = _ref.className,
      style = _ref.style,
      children = _ref.children;

  var _useContext = (0, _react.useContext)(_configContext.ConfigContext),
      clsPrefix = _useContext.clsPrefix;

  var _useContext2 = (0, _react.useContext)(_stepContext.StepContext),
      currentKey = _useContext2.currentKey,
      onChange = _useContext2.onChange,
      connectNode = _useContext2.connectNode,
      length = _useContext2.length,
      direction = _useContext2.direction;

  (0, _react.useEffect)(function () {
    if (currentKey === index) {
      onChange(index);
    }
  }, [currentKey]); // 渲染connect

  var renderConnect = function renderConnect() {
    if (connectNode) {
      return connectNode;
    } else {
      var _classNames;

      return /*#__PURE__*/_react.default.createElement("div", {
        className: (0, _classnames.default)((_classNames = {}, _defineProperty(_classNames, "".concat(clsPrefix, "-step-item__connect--vertical"), direction === 'vertical'), _defineProperty(_classNames, "".concat(clsPrefix, "-step-item__connect--horizontal"), direction === 'horizontal'), _classNames))
      });
    }
  };

  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
    key: index,
    className: (0, _classnames.default)(className, "".concat(clsPrefix, "-step-item"), (_classNames2 = {}, _defineProperty(_classNames2, "".concat(clsPrefix, "-step-item--vertical"), direction === 'vertical'), _defineProperty(_classNames2, "".concat(clsPrefix, "-step-item--horizontal"), direction === 'horizontal'), _classNames2)),
    style: style
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _classnames.default)("".concat(clsPrefix, "-step-item__index"), _defineProperty({}, "".concat(clsPrefix, "-step-item__index--active"), currentKey >= index))
  }, index + 1), /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _classnames.default)("".concat(clsPrefix, "-step-item__text"), (_classNames4 = {}, _defineProperty(_classNames4, "".concat(clsPrefix, "-step-item__text--active"), currentKey >= index), _defineProperty(_classNames4, "".concat(clsPrefix, "-step-item__text--vertical"), direction === 'vertical'), _defineProperty(_classNames4, "".concat(clsPrefix, "-step-item__text--horizontal"), direction === 'horizontal'), _classNames4))
  }, children)), index < length - 1 && renderConnect());
}